package ModelLayer;
import java.util.*;

public class ManagerContainer{
    private ArrayList<Manager>  managerContainer;
    private static ManagerContainer instance;

    private ManagerContainer(){
        managerContainer = new  ArrayList<Manager>();
    }

    public static ManagerContainer getInstance(){
        if (instance == null){
            instance = new ManagerContainer();
        }
        return instance;
    }

    public Manager findManagerByName(String name){
        Manager pObject = null;
        int index = 0;
        boolean found = false;
        while(index < managerContainer.size() && !found)
        {
            pObject = managerContainer.get(index); 
            if(pObject.getName().equals(name))
            {
                found = true;
            }
            else{
                index++;
            }
        }
         if(found){
           return managerContainer.get(index) ;
        }else{
            return  null;
        }
    }
    
    public Manager findManagerById(int id){
        Manager pObject = null;
        int index = 0;
        boolean found = false;
        while(index < managerContainer.size() && !found)
        {
            pObject = managerContainer.get(index); 
            if(pObject.getId() == id)
            {
                found = true;
            }
            else{
                index++;
            }
        }
          if(found){
           return managerContainer.get(index) ;
        }else{
            return  null;
        }
    }
    
    public void addManager(Manager p){
        managerContainer.add(p);
    }

    public void deleteManager(Manager p){
        if(managerContainer.contains(p))
            managerContainer.remove(p);
    }
}
